package views.structure
{
	import flash.display.Bitmap;
	import flash.display.Stage;
	import flash.events.Event;
	
	import mx.core.IVisualElement;
	
	import spark.components.Group;
	import spark.components.Image;
	
	public class Structure extends Group
	{
		protected var _stage:Stage;
		
		protected var backGround:Image;
		protected var content:Content;
		protected var popup:Popup;
		
		public function Structure( _stage:Stage, contentWidth:int, contentHeight:int )
		{
			super();
			
			
			this._stage = _stage;
			
			var stageWidth:int = _stage.width;
			
			var stageHeight:int = _stage.height;
			
			backGround = new Image();
			
			popup = new Popup();
			popup.width = stageWidth;
			popup.height = stageHeight;
			
			content = new Content( contentWidth, contentHeight );
			
			content.x = ( stageWidth - contentWidth ) / 2;
			
			content.y = ( stageHeight - contentHeight ) / 2;
			
			
			this.addElement( backGround );
			
			this.addElement( content );
			
			this.addElement( popup );
			
			
			_stage.addEventListener( Event.RESIZE, reposition );
			
		}
		
		public function reposition( event:Event ):void
		{
			content.x = ( stage.width - content.width ) / 2;
			
			content.y = ( stage.height - content.height ) / 2;
		}
		
		
		public function setBackGround( src:Object ):void
		{
			backGround.source = src;
		}
		
		public function addContent( elem:IVisualElement ):void
		{
			content.addElement( elem ); 
		}
		
		
		public function removeContent( elem:IVisualElement ):void
		{
			content.removeElement( elem );
		}
		 
		public function addPopup( elem:IVisualElement ):void
		{
			popup.addElement( elem ); 
		}
		
		public function removePopup( elem:IVisualElement ):void
		{
			popup.removeElement( elem );
		}
	}
}